package com.linewow.xhyy.nihaonew.fragment;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.linewow.xhyy.nihaonew.R;
import com.linewow.xhyy.nihaonew.activity.IMessageActivity;
import com.linewow.xhyy.nihaonew.base.BaseFragment;
import com.linewow.xhyy.nihaonew.event.MessageEvent;

import org.simple.eventbus.EventBus;
import org.simple.eventbus.Subscriber;
import org.simple.eventbus.ThreadMode;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by LXR on 2016/11/22.
 */
public class TestConversationFragment extends BaseFragment {
    @Bind(R.id.message_reply_icon)
    ImageView messageReplyIcon;
    @Bind(R.id.message_reply_tv)
    TextView messageReplyTv;
    @Bind(R.id.message_reply_arrow)
    ImageView messageReplyArrow;
    @Bind(R.id.message_reply_red)
    ImageView messageReplyRed;
    @Bind(R.id.message_reply_rela)
    RelativeLayout messageReplyRela;
    @Bind(R.id.message_like_icon)
    ImageView messageLikeIcon;
    @Bind(R.id.message_like_tv)
    TextView messageLikeTv;
    @Bind(R.id.message_like_arrow)
    ImageView messageLikeArrow;
    @Bind(R.id.message_like_red)
    ImageView messageLikeRed;
    @Bind(R.id.message_like_rela)
    RelativeLayout messageLikeRela;
    @Bind(R.id.message_system_icon)
    ImageView messageSystemIcon;
    @Bind(R.id.message_system_tv)
    TextView messageSystemTv;
    @Bind(R.id.message_system_arrow)
    ImageView messageSystemArrow;
    @Bind(R.id.message_system_red)
    ImageView messageSystemRed;
    @Bind(R.id.message_system_rela)
    RelativeLayout messageSystemRela;

    private String TAG="TestConversationFragment";
    @Override
    public View initView() {
        View view = View.inflate(getActivity(), R.layout.view_message_head, null);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void initList() {
        super.initList();
        EventBus.getDefault().register(TestConversationFragment.this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.message_reply_rela, R.id.message_like_rela, R.id.message_system_rela})
    public void onClick(View view) {
        Intent intent=new Intent(getActivity(), IMessageActivity.class);
        int id=view.getId();
        switch (id){
            case R.id.message_reply_rela:
                Log.e(TAG,"点击了 消息回复");
                intent.putExtra("info","loadpinglun");
                messageReplyRed.setVisibility(View.GONE);
                messageReplyArrow.setVisibility(View.VISIBLE);
                break;
            case R.id.message_like_rela:
                intent.putExtra("info","loadzan");
                messageLikeRed.setVisibility(View.GONE);
                messageLikeArrow.setVisibility(View.VISIBLE);
                break;
            case R.id.message_system_rela:
                intent.putExtra("info","loadtongzhi");
                messageSystemRed.setVisibility(View.GONE);
                messageSystemArrow.setVisibility(View.VISIBLE);
                break;
        }
        startActivity(intent);
    }


    @Subscriber(tag = "JPushReceiver",mode = ThreadMode.MAIN)
    private void pushMessageEvent(MessageEvent messageEvent){
        int index=messageEvent.getIndex();
        Log.e(TAG,"接受到了"+index);
        switch (index){
            case 1:
                messageSystemArrow.setVisibility(View.GONE);
                messageSystemRed.setVisibility(View.VISIBLE);
                break;
            case 2:
                messageLikeArrow.setVisibility(View.GONE);
                messageLikeRed.setVisibility(View.VISIBLE);
                break;
            case 3:
                messageReplyArrow.setVisibility(View.GONE);
                messageReplyRed.setVisibility(View.VISIBLE);
                break;
        }
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(TestConversationFragment.this);
    }
}
